How to Use substring() with Regular Expressions

To extract a substring using a regular expression, MySQL provides the function regexp_substr, which receives a source string and a pattern with the regular expression. The function regexp_substr returns a substring matching the regular expression.

select regexp_substr('hello how are you', ‘h[a-z]* ’) as a_word_starting_with_h;
a_word_starting_with_h
{hello}

MySQL provides another interesting function called regexp_like which returns a 0/1 flag indicating if the provided string matches the regular expression specified by the pattern in the second parameter.

select regexp_like('yellow', 'y[a-z]*w');
regexp_like
1

IN THIS PAGE